package com.example.financecollegeorderdish.ui.poup

import android.content.Context
import android.widget.CheckBox
import android.widget.TextView
import androidx.recyclerview.widget.RecyclerView
import com.drake.brv.utils.divider
import com.drake.brv.utils.linear
import com.drake.brv.utils.setup
import com.example.financecollegeorderdish.R
import com.example.financecollegeorderdish.bean.HealthRvBean
import com.example.financecollegeorderdish.bean.TasteRvBean
import com.lxj.xpopup.core.AttachPopupView

class TasteTagPoup(context: Context, var tasteList: List<TasteRvBean>) :
    AttachPopupView(context) {

    /**
     * 具体实现的类的布局
     *
     * @return
     */
    override fun getImplLayoutId(): Int = R.layout.poup_health_tag

    /**
     * do init.
     */
    override fun onCreate() {
        super.onCreate()
        findViewById<RecyclerView>(R.id.rv_health).apply {
            linear()
            animation = null
            divider(R.drawable.shape_detail_rv_divider)
            setup {
                addType<TasteRvBean>(R.layout.item_rv_main)
                onBind {
                    val model = getModel<TasteRvBean>()
                    val cb = findView<CheckBox>(R.id.cb)
                    val title = findView<TextView>(R.id.title)
                    cb.isChecked = model.isChecked
                    title.text = model.taste
                }
                onClick(R.id.item) {
                    when (it) {
                        R.id.item -> {
                            val model = getModel<TasteRvBean>()
                            getModel<TasteRvBean>().isChecked =
                                !getModel<TasteRvBean>().isChecked
                            notifyItemChanged(modelPosition)
                        }

                        else -> {

                        }
                    }
                }
            }.models = tasteList
        }
    }
}